package com.qf.shiro2203.contorller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/user")
public class LoginController {
    /**
     * 注销
     * @return
     */
    @GetMapping("/logout")
    public String logout(){
        //获取当前对象 shiro
        Subject subject = SecurityUtils.getSubject();
        //注销当前用户
        subject.logout();
        //重定向到登录页面
        return "redirect:/login.html";
    }
    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
/*    @PostMapping("/login")
    public String login(String username,String password){
        //基于shiro的登录方法
        //Subject代表当前用户信息的对象
        Subject subject = SecurityUtils.getSubject();
        //将用户提供的用户名和密码封装成 shiro中需要的  UsernamePasswordToken对象
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
        //让shiro处理登录的身份验证逻辑
        subject.login(usernamePasswordToken);
        *//*现在需要拿到数据库中的用户名和密码   在CustomRealm中*//*

        //返回登录成功
        *//*HashMap<String, Object> map = new HashMap<>();
        map.put("code",1);
        map.put("msg","ok");*//*

        return "redirect:/home.html";
    }*/
}
